<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">

    var count = (function () {
        var a = 0;

        function add() {
            a++;
            return a;
        }

        return add;

    })()

    count();
    count();

    var nowcount = count();

    alert(nowcount);

</script>
</body>
</html>